/*
	Author: Superxpdude
	
	Description:
	Tells the server to save a certain variable in the .ini Database
	
	Parameters:
	_this select 0: UID of client that needs to save data
	_this select 1: Unit of client that needs to save data
	_this select 2: (Array) Contains the type and value of data to save
	
	Example:
	array = ["playerUID","player", ["score",10]];
	
	Returns:
	BOOL: True if function processed without error, false if something went wrong
*/
private ["_playerUID","_player","_save"];

//Clear variables to use later
iniDB_saveRequest = nil;
iniDB_saveResponse = nil;

// Define variables to send to the server
_playerUID = [_this, 0, nil, [0]] call BIS_fnc_param;
_player = [_this, 1, objnull, [objnull]] call BIS_fnc_param;
_save = [_this, 2, ["error"], [[]]] call BIS_fnc_param;

// Check for invalid variables
if (isNil _playerUID) exitwith {["PlayerUID must be defined when calling the save function."] call BIS_fnc_error; false};
if (isNull _player) exitwith {["Player unit must be defined when calling the save function."] call BIS_fnc_error; false};
if ((getPlayerUID _player) != _playerUID) exitwith {["Player unit and PlayerUID do not match."] call BIS_fnc_error; false};
if ((_save select 0) == "error") exitwith {["Undefined save type."] call BIS_fnc_error; false};

// Send variables to the server
iniDB_saveRequest = [_playerUID, _player, _save];

// Wait for response from server
waitUntil {!isNil "iniDB_saveResponse"};

// Check if the server encountered an error
if (inidDB_saveResponse == false) exitWith {["The server had an error processing the save request."] call BIS_fnc_error; false};

// Delete variables to save space
iniDB_saveRequest = nil;
iniDB_saveResponse = nil;

// End the function
true